<?php
session_start();
error_reporting(1);

include("functions.php");

$logged = 0;

if(check_user($_POST["user"]) || $_SESSION["user"]){
	$logged = 1;
	$_SESSION["user"]=$_POST["user"];
}

if($_SESSION["user"]) $_POST["user"]=$_SESSION["user"];

$output='<dl class="slidedeck">	';
if($_POST["action"]=="login" && $logged){
		$output.='
			<dt>STATS</dt>
				<dd>
					STATS<hr />
					Logged in as <b>'.$_POST["user"].'</b><br />'.
					check_credits($_POST["user"])
				.'</dd>
			<dt>DETAILS</dt>
				<dd>
					Details<hr />'.
					check_details($_POST["user"])
				.'</dd>
			<dt>Invites</dt>
				<dd>
					INVITES<hr />'.
					check_invites($_POST["user"])
				.'</dd>';
	}
	elseif($_POST["action"]=="register"){
			
			$output.='<dt>Registration on the way</dt>
				<dd>'.register_user($_POST).'</dd>';
	}
	elseif(!$_POST["user"] || !$logged){ 
			$output.='
			<dt>LOGIN</dt>
				<dd>
					<b>Login to see stats</b><br />
					<form  method="post" id="login_form">
						E-mail: <input id="user_login" type="text" style="position: absolute; right: 25px;" name="user" /><br />
						<input type="hidden" name="action" value="login" />
						<br /><input type="submit" value="Authenticate" style="position: absolute; right: 25px;" /><br />
					</form><hr />';
			if(!$logged && $_POST["user"]) $output.="<b><font color='red'>E-mail not registered.</font><br />You must register in order to participate</b>";	
			$output.='
				</dd>			
			<dt>REGISTER</dt>
				<dd>
					<b>Not registered?</b><br />
					Create an account now and we will forever spam your inbox with crap.
					<form  method="post" id="reg_form">
						<input type="hidden" name="action" value="register" />
						E-mail: <input id="reg_user" type="text" style="position: absolute; right: 10px;" name="reg_user" /><br />
						Postcode: <input id="reg_code" type="text" style="position: absolute; right: 10px;" name="reg_code" /><br />
						Age: <input id="reg_age" type="text" style="position: absolute; right: 10px;" name="reg_age" /><br />
						Phone: <input id="reg_phone" type="text" style="position: absolute; right: 10px;" name="reg_phone" /><br />
						
						<input type="submit" value="Register" style="position: absolute; right: 10px;" /><br />
					</form><hr />
				</dd>';
			$output.='
				<script type="text/javascript">
					var options = { 
					target: "#slide_frame",   // target element(s) to be updated with server response 
					url: "side.php"       // override for forms action attribute
					}; 

				  // $("#reg_form").ajaxForm(options);
				   $("#login_form").ajaxForm(options);
				   
				   
				   $("#user_login").DefaultValue("Insert email to login.");
				   
				   $("#reg_user").DefaultValue("'.$reg_user.'");
				   $("#reg_code").DefaultValue("'.$reg_code.'");
				   $("#reg_age").DefaultValue("'.$reg_age.'");
				   $("#reg_phone").DefaultValue("'.$reg_phone.'");
				</script>';
	}

$output.='</dl>';
$output.='    
		<script type="text/javascript">
				$(".slidedeck").slidedeck();

		</script>';

echo $output;
?>
